<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input class="input" type="text" />

    <script>
      // 防抖-- 事件触发后，n秒后再执行回调
      const ipt = document.querySelector(".input");
      ipt.addEventListener("keyup", (e) => {
        test(e.target.value);
      });

      const test = debounce(ajax, 1200);

      function debounce(fn, delay) {
        let timer = null;
        return function (args) {
          clearTimeout(timer);
          timer = setTimeout(() => {
            fn.call(this, args);
          }, delay);
        };
      }
      function ajax(content) {
        console.log("ajax" + content);
      }
    </script>
  </body>
</html>
